<?php
//**************************************************************************************************
//==================================================================================================
//**************************************************************************************************
function form_load($msg = "", $tipo = "") {
	global $form_name;
	$txtNome = "";
	echo "<h4>" . montaLink (_MI_MOD_NAME, METODO_PADRAO, FORM_PADRAO) . " :: " . montaLink (_MI_MOD_XXX_MENU0) . "</h4>";
	if ($msg != '') {
		if ($tipo == "S") { //sucesso		
			xoops_result($msg, _MI_MOD_CAPTION_MSG_SUCESS);
			unset($_POST);
		} else if ($tipo == "E") { //erro
			xoops_error($msg, _MI_MOD_CAPTION_MSG_ERR);
			$txtNome = $_POST['txtNome'];
		}
	}
	xoops_load('xoopsformloader');	
	$form = new XoopsThemeForm(_MI_MOD_XXX_MENU0, $form_name . '_form', 'index.php', "post", true);
	$form->addElement(new XoopsFormHidden(FORM_PARAM, $form_name));
	$form->addElement(new XoopsFormHidden(FUNCTION_PARAM, 'exec'));
	//==================================================================================
	$form->addElement(new XoopsFormText(_MI_MP3PLAYER_GENERO, 'txtNome', 30, 30, $txtNome), true);	
	//==================================================================================	
	$form->addElement(new XoopsFormButton('', $form_name . '_submit', _SUBMIT, 'submit'));
	$form->display();
}
function form_exec() {
	$msg="";
	$tipo="E";//erro
	
    if ($GLOBALS['xoopsSecurity']->check()) {
		if (trim($_POST['txtNome']) == '') {
			$msg  = _MI_MOD_ADD_CATEGORIA_NOME_OBRIGATORIO;
		} else if (form_insert($_POST['txtNome'])) {
			$msg  = _MI_MP3PLAYER_GENERO_SUCESS;
			$tipo = "S";//sucess
		} else {
			$msg = _MI_MP3PLAYER_ERR_SQL_INSERT_GENERO;
		}
	}
	form_load($msg, $tipo);
}

function form_insert($nome) {
	global $xoopsUser;	
	$genero_handler =& xoops_getmodulehandler('mp3player_genero');
	$genero =& $genero_handler->create();
	$genero->setVar('nome', $nome);
	$retorno = $genero_handler->insert($genero);
	unset($genero_handler);
	return $retorno;
}
//**************************************************************************************************
//==================================================================================================
//**************************************************************************************************
?>